package com.att.action;

import com.adkfp.utils.LayuiUtil;
import com.att.bean.*;
import com.att.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("numRun")
public class NumRunAction {

    @Resource(name = "numRunService")
    private NumRunService numRunService;
    @Resource(name = "userSpedayService")
    private UserSpedayService userSpedayService;
    @Resource(name = "accessLogService")
    private AccessLogService accessLogService;
    @Resource(name = "paramService")
    private ParamService paramService;
    @Resource(name = "leaveClass1Service")
    private LeaveClass1Service leaveClass1Service;
    @Resource(name = "userOfRunDeilService")
    private UserOfRunDeilService userOfRunDeilService;

    /**
     * Description: 带条件查询班次管理记录
     *
     * @param bean
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll(NumRunBean bean) {
        List<NumRunBean> list = numRunService.findByCondition(bean);
        return LayuiUtil.data(0L, list);
    }

    /**
     * Description: 转发到页面
     */
    @RequestMapping("numRunIndex")
    public String numRunIndex() {
        return "settings/numRun";
    }


    //新增
    @RequestMapping("insert")
    @ResponseBody
    public String insert(NumRunBean bean) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = format.parse("2099-12-31 00:00:00");
        bean.setEndTime(date);
        boolean flag = numRunService.insert(bean);
        if (flag) {
            return "SUCCESS";
        }
        return "ERROR";
    }

    //修改
    @RequestMapping("update")
    @ResponseBody
    public String update(NumRunBean bean) {
        boolean flag = numRunService.update(bean);
        if (flag) {
            return "SUCCESS";
        }
        return "ERROR";
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public String delete(Integer id) {
        System.out.println("MCM----------" + id);
        boolean flag = numRunService.delete(id);
        if (flag) {
            return "SUCCESS";
        }
        return "ERROR";
    }

    /**
     * Description: 查询班次名称
     */
    @RequestMapping("selectNumRunName")
    @ResponseBody
    public Object selectNumRunName() {
        List<NumRunBean> list = numRunService.findNumRunName();
        return list;
    }

    /**
     * Description: 带条件查询班次班次明细情况
     *
     * @param bean
     */
    @RequestMapping("findNumRunBean")
    @ResponseBody
    public Object findNumRunBean(NumRunBean bean) throws ParseException {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat format2 = new SimpleDateFormat("HH:mm:ss");
        SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateFormat df3 = DateFormat.getTimeInstance();
        Calendar cal = Calendar.getInstance();
        ParamBean paramBean = new ParamBean();
        List<ParamBean> paramBeanList = paramService.findByCondition(paramBean);
        long count = numRunService.findNumRunBeanCount(bean);
        List<NumRunBean> list = numRunService.findNumRunBeanCondition(bean);
        int size = 1;
        for (int i = 0; i < list.size(); i++) {
            if (i > 0) {
                if (list.get(i).getUserName() != null) {
                    if (!list.get(i).getUserName().equals(list.get(i - 1)
                            .getUserName())) {
                        size = 1;
                    } else {
                        size++;
                    }
                } else {
                    size = 1;
                }
            }
//            Integer lateArrive = 0;//迟到
//            Integer leaveEarly = 0;//早退
            Integer absenteeism = 2;//旷工
            Integer allWorkTime = 0;//工作时间
            list.get(i).setNumRunNo(size);
            if (list.get(i).getDeilStartTime() != null) {
                String dayTime = format.format(list.get(i).getDeilStartTime());
                list.get(i).setStartTimeStr(dayTime);
                UserSpedayBean userSpedayBean = new UserSpedayBean();
                userSpedayBean.setUserId(list.get(i).getUserId());
                userSpedayBean.setStartTime(list.get(i).getRunStartTime());
                userSpedayBean.setEndTime(list.get(i).getRunEndTime());
                List<UserSpedayBean> userSpedayInfo = userSpedayService.findUserSpedayBean(userSpedayBean);
                for (int k = 0; k < userSpedayInfo.size(); k++) {
                    Date date = format.parse(format.format(userSpedayInfo.get(k).getStartTime()));
                    Date endDate = format.parse(format.format(userSpedayInfo.get(k).getEndTime()));
                    int days = (int) ((endDate.getTime() - date.getTime()) / (1000 * 3600 * 24));
                    days = days + 1;
                    Calendar calendar = Calendar.getInstance();
                    for (int j = 0; j < days; j++) {
                        if (j == 0) {
                            calendar.setTime(userSpedayInfo.get(k).getStartTime());
                            date = calendar.getTime();
                            Date date1 = format.parse(format.format(date));
                            if (date1.compareTo(format.parse(dayTime)) == 0) {
                                list.get(i).setLeaveName(userSpedayInfo.get(k).getLeaveName());
                                list.get(i).setSymbol(userSpedayInfo.get(k).getReportSymbol());
                                absenteeism = 0;
                                list.get(i).setAbsenteeism(absenteeism);
                            }
                        } else if (j > 0 && days > 1) {
                            calendar.setTime(userSpedayInfo.get(k).getStartTime());
                            calendar.add(Calendar.DAY_OF_MONTH, 1);
                            date = calendar.getTime();
                            Date date1 = format.parse(format.format(date));
                            if (date1.compareTo(format.parse(dayTime)) == 0) {
                                list.get(i).setLeaveName(userSpedayInfo.get(k).getLeaveName());
                                list.get(i).setSymbol(userSpedayInfo.get(k).getReportSymbol());
                                absenteeism = 0;
                                list.get(i).setAbsenteeism(absenteeism);
                            }
                        }
                    }

                }
                if (list.get(i).getSchStartTime() != null && list.get(i).getSchEndTime() != null
                        && list.get(i).getCheckInTime1() != null && list.get(i).getCheckOutTime1() != null && list.get(i).getCheckInTime2() != null
                        && list.get(i).getCheckOutTime2() != null && list.get(i).getRunStartTime() != null
                        && list.get(i).getRunEndTime() != null) {
                    String startTime = format2.format(list.get(i).getSchStartTime());
                    list.get(i).setSchStartTimeStr(startTime.substring(0, startTime.lastIndexOf(":")));
                    String endTime = format2.format(list.get(i).getSchEndTime());
                    list.get(i).setSchEndTimeStr(endTime.substring(0, endTime.lastIndexOf(":")));
                    Date schStartTime = format2.parse(df3.format(list.get(i).getSchStartTime()));
                    Date schEndTime = format2.parse(df3.format(list.get(i).getSchEndTime()));
                    Date checkInTime1 = format2.parse(df3.format(list.get(i).getCheckInTime1()));
                    Date checkInTime2 = format2.parse(df3.format(list.get(i).getCheckInTime2()));
                    Date checkOutTime1 = format2.parse(df3.format(list.get(i).getCheckOutTime1()));
                    Date checkOutTime2 = format2.parse(df3.format(list.get(i).getCheckOutTime2()));
                    if (bean.getEndTime() == null) {
                        if (list.get(i).getUserId() != null) {
                            AccessLogBean accessLogBean = new AccessLogBean();
                            String userID = list.get(i).getUserId();
                            accessLogBean.setUserID(userID);
                            accessLogBean.setCheckType(1);
                            List<AccessLogBean> list1 = accessLogService.findAccessLogBean(accessLogBean);
                            for (int j = 0; j < list1.size(); j++) {

                                if (paramBeanList.get(0).getClassTimeSlot() == 0 && schEndTime.before(schStartTime)) {
                                    if (j > 0) {
                                        Calendar c1 = Calendar.getInstance();
                                        Calendar c2 = Calendar.getInstance();
                                        Date eventTime1 = format3.parse(list1.get(j).getEventTime());
                                        c1.setTime(eventTime1);
                                        Date eventTime = format3.parse(list1.get(j - 1).getEventTime());
                                        c2.setTime(eventTime);
                                        int days = c1.get(Calendar.DAY_OF_MONTH) - c2.get(Calendar.DAY_OF_MONTH);
                                        if (days == 1) {
                                            if (list1.get(j).getCheckType() == null) {
                                                list1.get(j).setCheckType(1);
                                            }
                                            Date date2 = format.parse(format.format(eventTime));
                                            if (date2.compareTo(format.parse(dayTime)) == 0) {
                                                Date eventTime2 = format2.parse(df3.format(eventTime1));
                                                if ((eventTime2.compareTo(checkOutTime1) == 0 || eventTime2.after(checkOutTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2)) && list1.get(j).getCheckType() == 1) {
                                                    list.get(i).setCheckOutTime1Str(format2.format(eventTime2));
                                                    if (list.get(i).getWorkMins() != null) {
                                                        long time = list.get(i).getWorkMins() * 60000;
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                            int minute = (int) Math.floor((time % 3600000) / 60000);
                                                            int workdayTime = list.get(i).getWorkMins();
                                                            int workdayHours = workdayTime / 60;
                                                            int workdayMins = workdayTime % 60;
                                                            String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                            if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                if (workdayMins == 0) {
                                                                    workdayMins = 60;
                                                                    hours = workdayHours - 1;
                                                                    minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                }
                                                                if (String.valueOf(hours).length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (String.valueOf(minute).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        } else {
                                                            String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                            String minute = String.valueOf((time % 3600000) / 60000);
                                                            if (hours.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                if (minute.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                }
                                                            } else {
                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
                                                            }
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }
                                                    if (eventTime2.compareTo(schEndTime) == 0 || eventTime2.before(schEndTime)) {
                                                        long num2 = schEndTime.getTime() - eventTime2.getTime();
                                                        // 计算差多少小时
                                                        long hour2 = num2 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min2 = num2 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec2 = num2 % nd % nh % nm / ns;
                                                        if ((num2 / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 1;
                                                        }
                                                        cal.setTime(schEndTime);
                                                        if (paramBeanList != null && paramBeanList.get(0).getOffWorkTime() != null) {
                                                            cal.add(Calendar.MINUTE, -paramBeanList.get(0).getOffWorkTime());
                                                        }
                                                        Date startdate2 = format2.parse(df3.format(cal.getTime()));
                                                        if (eventTime2.compareTo(startdate2) == 0 || eventTime2.before(startdate2)) {
                                                            list.get(i).setCheckOutTime2Str(hour2 + ":" + min2 + ":" + sec2);
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            time = time - num2;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);
                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;
                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                            LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                            leaveClass1Bean.setLeaveName("早退");
                                                            List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                            list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                        } else {
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null && list.get(i).getCheckOutTime1Str() != null) {
                                                        long num3 = format2.parse(list.get(i).getCheckOutTime1Str()).getTime() - format2.parse(list.get(i).getCheckInTime1Str()).getTime();
                                                        // 计算差多少小时
                                                        long hour3 = num3 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min3 = num3 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec3 = num3 % nd % nh % nm / ns;
                                                        list.get(i).setAttendanceTime((hour3 + 24) + ":" + min3 + ":" + sec3);
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour >= paramBeanList.get(0).getAbsenteeism()) {
                                                            list.get(i).setAttendanceTime(null);
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }

                                                    if (list.get(i).getSchName().equals("加班")) {
                                                        int workMins = list.get(i).getWorkMins();
                                                        list.get(i).setAllWorkTime(null);
                                                        if (list.get(i).getCheckOutTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                    }
                                                    if (list.get(i).getCheckOutTime1Str() != null) {
                                                        absenteeism = 0;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                    }
                                                } else {
                                                    if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                        if (list.get(i).getCheckOutTime1Str() == null) {
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }
                                                }
                                                if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                    if (list.get(i).getCheckInTime1Str() == null) {
                                                        absenteeism = 1;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                        list.get(i).setAllWorkTime(null);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                Date eventTime = format3.parse(list1.get(j).getEventTime());
                                if (eventTime != null) {
                                    Date eventTime2 = format2.parse(df3.format(eventTime));
                                    if (eventTime.after(list.get(i).getRunStartTime()) && eventTime.before(list.get(i).getRunEndTime())) {
                                        Date date = format.parse(format.format(eventTime));
                                        if (date.compareTo(format.parse(dayTime)) == 0) {
//                                            if ((eventTime2.compareTo(checkInTime1) == 0 || eventTime2.after(checkInTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2))) {
                                            if ((eventTime2.compareTo(checkInTime1) == 0 || eventTime2.after(checkInTime1)) && (eventTime2.compareTo(checkInTime2) == 0 || eventTime2.before(checkInTime2))) {
                                                if (paramBeanList.get(0).getOffDutyNoAttend() == 1) {
                                                    if (list.get(i).getWorkMins() != null) {
                                                        int time = list.get(i).getWorkMins();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                            if (minute.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                            }
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }
                                                }
                                                list.get(i).setCheckInTime1Str(format2.format(eventTime2));
                                                if (eventTime2.after(schStartTime)) {//eventTime2.compareTo(schStartTime) == 0 ||
                                                    long num = eventTime2.getTime() - schStartTime.getTime();
                                                    // 计算差多少小时
                                                    long hour = num % nd / nh;
                                                    // 计算差多少分钟
                                                    long min = num % nd % nh / nm;
                                                    // 计算差多少秒//输出结果
                                                    long sec = num % nd % nh % nm / ns;
                                                    if ((num / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                        absenteeism = 1;
                                                    }
                                                    cal.setTime(list.get(i).getSchStartTime());
                                                    if (paramBeanList != null && paramBeanList.get(0).getOverTime() != null) {
                                                        cal.set(Calendar.MINUTE, paramBeanList.get(0).getOverTime());
                                                    }
                                                    Date startdate = format2.parse(df3.format(cal.getTime()));
                                                    if ((eventTime2.compareTo(startdate) == 0 || eventTime2.after(startdate)) && (eventTime2.compareTo(checkInTime2) == 0 || eventTime2.before(checkInTime2))) {
                                                        list.get(i).setCheckInTime2Str(hour + ":" + min + ":" + sec);
//                                                            long time = list.get(i).getWorkMins() * 60000;
//                                                            time = time - num;
//                                                            String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
//                                                            String minute = String.valueOf((time % 3600000) / 60000);
//                                                            if (hours.length() == 1) {
//                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
//                                                                if (minute.length() == 1) {
//                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
//                                                                }
//                                                            } else {
//                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
//                                                            }
                                                        LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                        leaveClass1Bean.setLeaveName("迟到");
                                                        List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                        list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                    }
                                                }
                                                if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                    if (list.get(i).getCheckInTime1Str() == null) {
                                                        absenteeism = 1;
                                                        list.get(i).setAllWorkTime(null);
                                                    }
                                                }
                                                if (list.get(i).getSchName().equals("加班")) {
                                                    int workMins = list.get(i).getWorkMins();
                                                    list.get(i).setAllWorkTime(null);
                                                    if (list.get(i).getCheckOutTime2Str() != null) {
                                                        String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                        int hour = Integer.valueOf(time2[0]);
                                                        int min = Integer.valueOf(time2[1]);
                                                        int second = Integer.valueOf(time2[2]);
                                                        if (hour > 0) {
                                                            workMins = workMins - (hour * 60);
                                                        }
                                                        if (min > 0) {
                                                            workMins = workMins - (min);
                                                        }
                                                        if (second > 0) {
                                                            workMins = workMins - (second / 60);
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(time2[0]);
                                                        int min = Integer.valueOf(time2[1]);
                                                        int second = Integer.valueOf(time2[2]);
                                                        if (hour > 0) {
                                                            workMins = workMins - (hour * 60);
                                                        }
                                                        if (min > 0) {
                                                            workMins = workMins - (min);
                                                        }
                                                        if (second > 0) {
                                                            workMins = workMins - (second / 60);
                                                        }
                                                    }
                                                    list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                }
                                            }
                                            if (list1.get(j).getCheckType() == null) {
                                                list1.get(j).setCheckType(1);
                                            }
                                            if (schEndTime.after(schStartTime)) {
                                                if ((eventTime2.compareTo(checkOutTime1) == 0 || eventTime2.after(checkOutTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2)) && list1.get(j).getCheckType() == 1) {
                                                    list.get(i).setCheckOutTime1Str(format2.format(eventTime2));

                                                    if (list.get(i).getWorkMins() != null) {
                                                        long time = list.get(i).getWorkMins() * 60000;
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            long num = eventTime2.getTime() - schStartTime.getTime();
                                                            // 计算差多少小时
                                                            long hour = num % nd / nh;
                                                            // 计算差多少分钟
                                                            long min = num % nd % nh / nm;
                                                            // 计算差多少秒//输出结果
                                                            long sec = num % nd % nh % nm / ns;
                                                            int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                            int minute = (int) Math.floor((time % 3600000) / 60000);

                                                            int workdayTime = list.get(i).getWorkMins();
                                                            int workdayHours = workdayTime / 60;
                                                            int workdayMins = workdayTime % 60;

                                                            String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                            if (workdayMins == 0) {
                                                                workdayMins = 60;
                                                                hours = workdayHours - 1;
                                                                minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                            }
                                                            if (String.valueOf(hours).length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                if (String.valueOf(minute).length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                }
                                                            } else {
                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
                                                            }
                                                        } else {
                                                            String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                            String minute = String.valueOf((time % 3600000) / 60000);
                                                            if (hours.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                if (minute.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                }
                                                            } else {
                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
                                                            }
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }

                                                    if (eventTime2.compareTo(schEndTime) == 0 || eventTime2.before(schEndTime)) {
                                                        long num2 = schEndTime.getTime() - eventTime2.getTime();
                                                        // 计算差多少小时
                                                        long hour2 = num2 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min2 = num2 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec2 = num2 % nd % nh % nm / ns;
                                                        if ((num2 / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 1;
                                                        }
                                                        cal.setTime(schEndTime);
                                                        if (paramBeanList != null && paramBeanList.get(0).getOffWorkTime() != null) {
                                                            cal.add(Calendar.MINUTE, -paramBeanList.get(0).getOffWorkTime());
                                                        }
                                                        Date startdate2 = format2.parse(df3.format(cal.getTime()));
                                                        if (eventTime2.compareTo(startdate2) == 0 || eventTime2.before(startdate2)) {
                                                            list.get(i).setCheckOutTime2Str(hour2 + ":" + min2 + ":" + sec2);
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            time = time - num2;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                            LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                            leaveClass1Bean.setLeaveName("早退");
                                                            List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                            list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                        } else {
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null && list.get(i).getCheckOutTime1Str() != null) {
                                                        long num3 = format2.parse(list.get(i).getCheckOutTime1Str()).getTime() - format2.parse(list.get(i).getCheckInTime1Str()).getTime();
                                                        // 计算差多少小时
                                                        long hour3 = num3 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min3 = num3 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec3 = num3 % nd % nh % nm / ns;
                                                        list.get(i).setAttendanceTime(hour3 + ":" + min3 + ":" + sec3);
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour >= paramBeanList.get(0).getAbsenteeism()) {
                                                            list.get(i).setAttendanceTime(null);
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }

                                                    if (list.get(i).getSchName().equals("加班")) {
                                                        int workMins = list.get(i).getWorkMins();
                                                        list.get(i).setAllWorkTime(null);
                                                        if (list.get(i).getCheckOutTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null) {
                                                        absenteeism = 0;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                    }
                                                } else {
                                                    if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                        if (list.get(i).getCheckOutTime1Str() == null) {
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }
                                                }
                                                if (list.get(i).getCheckOutTime1Str() != null) {
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 0;
                                                            continue;
                                                        }else {
                                                            absenteeism = 1;
                                                            continue;
                                                        }
                                                    }
                                                }
                                            }
                                            if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                if (list.get(i).getCheckInTime1Str() == null) {
                                                    absenteeism = 1;
                                                    list.get(i).setAbsenteeism(absenteeism);
                                                    list.get(i).setAllWorkTime(null);
                                                }
                                            }
                                        }
                                    }
                                    int a = list1.size() - 1;
                                    if (j == a) {
                                        if (absenteeism != 0) {
                                            absenteeism = 1;
                                            list.get(i).setAbsenteeism(absenteeism);
                                        }
                                    }
                                }
                            }
                            if (list1.size() <= 0) {
                                if (absenteeism != 0) {
                                    absenteeism = 1;
                                    list.get(i).setAbsenteeism(absenteeism);
                                }
                            }
                        }
                    }
                    if (bean.getEndTime() != null) {
                        if (list.get(i).getUserId() != null) {
                            AccessLogBean accessLogBean = new AccessLogBean();
                            String userID = list.get(i).getUserId();
                            accessLogBean.setUserID(userID);
                            accessLogBean.setCheckType(1);
                            List<AccessLogBean> list1 = accessLogService.findAccessLogBean(accessLogBean);
                            for (int j = 0; j < list1.size(); j++) {
                                if (paramBeanList.get(0).getClassTimeSlot() == 0 && schEndTime.before(schStartTime)) {
                                    if (j > 0) {
                                        Calendar c1 = Calendar.getInstance();
                                        Calendar c2 = Calendar.getInstance();
                                        Date eventTime1 = format3.parse(list1.get(j).getEventTime());
                                        c1.setTime(eventTime1);
                                        Date eventTime = format3.parse(list1.get(j - 1).getEventTime());
                                        c2.setTime(eventTime);
                                        int days = c1.get(Calendar.DAY_OF_MONTH) - c2.get(Calendar.DAY_OF_MONTH);
                                        if (days == 1) {
                                            if (list1.get(j).getCheckType() == null) {
                                                list1.get(j).setCheckType(1);
                                            }
                                            Date date2 = format.parse(format.format(eventTime));
                                            if (date2.compareTo(format.parse(dayTime)) == 0) {
                                                Date eventTime2 = format2.parse(df3.format(eventTime1));
                                                if ((eventTime2.compareTo(checkOutTime1) == 0 || eventTime2.after(checkOutTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2)) && list1.get(j).getCheckType() == 1) {
                                                    list.get(i).setCheckOutTime1Str(format2.format(eventTime2));
                                                    if (list.get(i).getWorkMins() != null) {
                                                        long time = list.get(i).getWorkMins() * 60000;
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                            int minute = (int) Math.floor((time % 3600000) / 60000);
                                                            int workdayTime = list.get(i).getWorkMins();
                                                            int workdayHours = workdayTime / 60;
                                                            int workdayMins = workdayTime % 60;
                                                            String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                            if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                if (workdayMins == 0) {
                                                                    workdayMins = 60;
                                                                    hours = workdayHours - 1;
                                                                    minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                }
                                                                if (String.valueOf(hours).length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (String.valueOf(minute).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        } else {
                                                            String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                            String minute = String.valueOf((time % 3600000) / 60000);
                                                            if (hours.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                if (minute.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                }
                                                            } else {
                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
                                                            }
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }
                                                    if (eventTime2.compareTo(schEndTime) == 0 || eventTime2.before(schEndTime)) {
                                                        long num2 = schEndTime.getTime() - eventTime2.getTime();
                                                        // 计算差多少小时
                                                        long hour2 = num2 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min2 = num2 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec2 = num2 % nd % nh % nm / ns;
                                                        if ((num2 / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 1;
                                                        }
                                                        cal.setTime(schEndTime);
                                                        if (paramBeanList != null && paramBeanList.get(0).getOffWorkTime() != null) {
                                                            cal.add(Calendar.MINUTE, -paramBeanList.get(0).getOffWorkTime());
                                                        }
                                                        Date startdate2 = format2.parse(df3.format(cal.getTime()));
                                                        if (eventTime2.compareTo(startdate2) == 0 || eventTime2.before(startdate2)) {
                                                            list.get(i).setCheckOutTime2Str(hour2 + ":" + min2 + ":" + sec2);
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            time = time - num2;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);
                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;
                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                            LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                            leaveClass1Bean.setLeaveName("早退");
                                                            List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                            list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                        } else {
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null && list.get(i).getCheckOutTime1Str() != null) {
                                                        long num3 = format2.parse(list.get(i).getCheckOutTime1Str()).getTime() - format2.parse(list.get(i).getCheckInTime1Str()).getTime();
                                                        // 计算差多少小时
                                                        long hour3 = num3 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min3 = num3 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec3 = num3 % nd % nh % nm / ns;
                                                        list.get(i).setAttendanceTime((hour3 + 24) + ":" + min3 + ":" + sec3);
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour >= paramBeanList.get(0).getAbsenteeism()) {
                                                            list.get(i).setAttendanceTime(null);
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }

                                                    if (list.get(i).getSchName().equals("加班")) {
                                                        int workMins = list.get(i).getWorkMins();
                                                        list.get(i).setAllWorkTime(null);
                                                        if (list.get(i).getCheckOutTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                    }
                                                    if (list.get(i).getCheckOutTime1Str() != null) {
                                                        absenteeism = 0;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                    }
                                                } else {
                                                    if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                        if (list.get(i).getCheckOutTime1Str() == null) {
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }
                                                }
                                                if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                    if (list.get(i).getCheckInTime1Str() == null) {
                                                        absenteeism = 1;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                        list.get(i).setAllWorkTime(null);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                Date eventTime = format3.parse(list1.get(j).getEventTime());
                                if (eventTime != null) {
                                    Date eventTime2 = format2.parse(df3.format(eventTime));
                                    if (eventTime.after(list.get(i).getRunStartTime()) && eventTime.before(list.get(i).getRunEndTime())) {
                                        Date date = format.parse(format.format(eventTime));
                                        if (date.compareTo(format.parse(dayTime)) == 0) {
//                                            if ((eventTime2.compareTo(checkInTime1) == 0 || eventTime2.after(checkInTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2))) {
                                            if ((eventTime2.compareTo(checkInTime1) == 0 || eventTime2.after(checkInTime1)) && (eventTime2.compareTo(checkInTime2) == 0 || eventTime2.before(checkInTime2))) {
                                                if (paramBeanList.get(0).getOffDutyNoAttend() == 1) {
                                                    if (list.get(i).getWorkMins() != null) {
                                                        int time = list.get(i).getWorkMins();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                            if (minute.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                            }
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }
                                                }
                                                list.get(i).setCheckInTime1Str(format2.format(eventTime2));
                                                if (eventTime2.after(schStartTime)) {//eventTime2.compareTo(schStartTime) == 0 ||
                                                    long num = eventTime2.getTime() - schStartTime.getTime();
                                                    // 计算差多少小时
                                                    long hour = num % nd / nh;
                                                    // 计算差多少分钟
                                                    long min = num % nd % nh / nm;
                                                    // 计算差多少秒//输出结果
                                                    long sec = num % nd % nh % nm / ns;
                                                    if ((num / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                        absenteeism = 1;
                                                    }
                                                    cal.setTime(list.get(i).getSchStartTime());
                                                    if (paramBeanList != null && paramBeanList.get(0).getOverTime() != null) {
                                                        cal.set(Calendar.MINUTE, paramBeanList.get(0).getOverTime());
                                                    }
                                                    Date startdate = format2.parse(df3.format(cal.getTime()));
                                                    if ((eventTime2.compareTo(startdate) == 0 || eventTime2.after(startdate)) && (eventTime2.compareTo(checkInTime2) == 0 || eventTime2.before(checkInTime2))) {
                                                        list.get(i).setCheckInTime2Str(hour + ":" + min + ":" + sec);
                                                        LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                        leaveClass1Bean.setLeaveName("迟到");
                                                        List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                        list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                    }
                                                }
                                                if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                    if (list.get(i).getCheckInTime1Str() == null) {
                                                        absenteeism = 1;
                                                        list.get(i).setAllWorkTime(null);
                                                    }
                                                }
                                                if (list.get(i).getSchName().equals("加班")) {
                                                    int workMins = list.get(i).getWorkMins();
                                                    list.get(i).setAllWorkTime(null);
                                                    if (list.get(i).getCheckOutTime2Str() != null) {
                                                        String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                        int hour = Integer.valueOf(time2[0]);
                                                        int min = Integer.valueOf(time2[1]);
                                                        int second = Integer.valueOf(time2[2]);
                                                        if (hour > 0) {
                                                            workMins = workMins - (hour * 60);
                                                        }
                                                        if (min > 0) {
                                                            workMins = workMins - (min);
                                                        }
                                                        if (second > 0) {
                                                            workMins = workMins - (second / 60);
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(time2[0]);
                                                        int min = Integer.valueOf(time2[1]);
                                                        int second = Integer.valueOf(time2[2]);
                                                        if (hour > 0) {
                                                            workMins = workMins - (hour * 60);
                                                        }
                                                        if (min > 0) {
                                                            workMins = workMins - (min);
                                                        }
                                                        if (second > 0) {
                                                            workMins = workMins - (second / 60);
                                                        }
                                                    }
                                                    list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                }
                                            }
                                            if (list1.get(j).getCheckType() == null) {
                                                list1.get(j).setCheckType(1);
                                            }
                                            if (schEndTime.after(schStartTime)) {
                                                if ((eventTime2.compareTo(checkOutTime1) == 0 || eventTime2.after(checkOutTime1)) && (eventTime2.compareTo(checkOutTime2) == 0 || eventTime2.before(checkOutTime2)) && list1.get(j).getCheckType() == 1) {
                                                    list.get(i).setCheckOutTime1Str(format2.format(eventTime2));

                                                    if (list.get(i).getWorkMins() != null) {
                                                        long time = list.get(i).getWorkMins() * 60000;
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                            int minute = (int) Math.floor((time % 3600000) / 60000);

                                                            int workdayTime = list.get(i).getWorkMins();
                                                            int workdayHours = workdayTime / 60;
                                                            int workdayMins = workdayTime % 60;

                                                            String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                            if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                if (workdayMins == 0) {
                                                                    workdayMins = 60;
                                                                    hours = workdayHours - 1;
                                                                    minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                }
                                                                if (String.valueOf(hours).length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (String.valueOf(minute).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        } else {
                                                            String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                            String minute = String.valueOf((time % 3600000) / 60000);
                                                            if (hours.length() == 1) {
                                                                list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                if (minute.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                }
                                                            } else {
                                                                list.get(i).setAllWorkTime(hours + ":" + minute);
                                                            }
                                                        }
                                                    } else {
                                                        int time = list.get(i).getWorkTime();
                                                        String hours = String.valueOf((int) Math.floor(time / 60));
                                                        String minute = String.valueOf(time % 60);
                                                        if (hours.length() == 1) {
                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                        } else {
                                                            list.get(i).setAllWorkTime(hours + ":" + minute);
                                                        }
                                                    }

                                                    if (eventTime2.compareTo(schEndTime) == 0 || eventTime2.before(schEndTime)) {
                                                        long num2 = schEndTime.getTime() - eventTime2.getTime();
                                                        // 计算差多少小时
                                                        long hour2 = num2 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min2 = num2 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec2 = num2 % nd % nh % nm / ns;
                                                        if ((num2 / 1000 / 60) > paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 1;
                                                        }
                                                        cal.setTime(schEndTime);
                                                        if (paramBeanList != null && paramBeanList.get(0).getOffWorkTime() != null) {
                                                            cal.add(Calendar.MINUTE, -paramBeanList.get(0).getOffWorkTime());
                                                        }
                                                        Date startdate2 = format2.parse(df3.format(cal.getTime()));
                                                        if (eventTime2.compareTo(startdate2) == 0 || eventTime2.before(startdate2)) {
                                                            list.get(i).setCheckOutTime2Str(hour2 + ":" + min2 + ":" + sec2);
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            time = time - num2;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                            LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                                                            leaveClass1Bean.setLeaveName("早退");
                                                            List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                                                            list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                                                        } else {
                                                            long time = list.get(i).getWorkMins() * 60000;
                                                            if (list.get(i).getCheckInTime2Str() != null) {
                                                                int hours = (int) Math.floor(time / (1000 * 60 * 60));
                                                                int minute = (int) Math.floor((time % 3600000) / 60000);

                                                                int workdayTime = list.get(i).getWorkMins();
                                                                int workdayHours = workdayTime / 60;
                                                                int workdayMins = workdayTime % 60;

                                                                String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                                int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                                if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                                    if (workdayMins == 0) {
                                                                        workdayMins = 60;
                                                                        hours = workdayHours - 1;
                                                                        minute = workdayMins - Integer.valueOf(checkInTime[1]);
                                                                    }
                                                                    if (String.valueOf(hours).length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                        if (String.valueOf(minute).length() == 1) {
                                                                            list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                        }
                                                                    } else {
                                                                        list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                    }
                                                                }
                                                            } else {
                                                                String hours = String.valueOf((int) Math.floor(time / (1000 * 60 * 60)));
                                                                String minute = String.valueOf((time % 3600000) / 60000);
                                                                if (hours.length() == 1) {
                                                                    list.get(i).setAllWorkTime("0" + hours + ":" + minute);
                                                                    if (minute.length() == 1) {
                                                                        list.get(i).setAllWorkTime("0" + hours + ":" + "0" + minute);
                                                                    }
                                                                } else {
                                                                    list.get(i).setAllWorkTime(hours + ":" + minute);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null && list.get(i).getCheckOutTime1Str() != null) {
                                                        long num3 = format2.parse(list.get(i).getCheckOutTime1Str()).getTime() - format2.parse(list.get(i).getCheckInTime1Str()).getTime();
                                                        // 计算差多少小时
                                                        long hour3 = num3 % nd / nh;
                                                        // 计算差多少分钟
                                                        long min3 = num3 % nd % nh / nm;
                                                        // 计算差多少秒//输出结果
                                                        long sec3 = num3 % nd % nh % nm / ns;
                                                        list.get(i).setAttendanceTime(hour3 + ":" + min3 + ":" + sec3);
                                                    }
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour >= paramBeanList.get(0).getAbsenteeism()) {
                                                            list.get(i).setAttendanceTime(null);
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }

                                                    if (list.get(i).getSchName().equals("加班")) {
                                                        int workMins = list.get(i).getWorkMins();
                                                        list.get(i).setAllWorkTime(null);
                                                        if (list.get(i).getCheckOutTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckOutTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        if (list.get(i).getCheckInTime2Str() != null) {
                                                            String[] time2 = list.get(i).getCheckInTime2Str().split(":");
                                                            int hour = Integer.valueOf(time2[0]);
                                                            int min = Integer.valueOf(time2[1]);
                                                            int second = Integer.valueOf(time2[2]);
                                                            if (hour > 0) {
                                                                workMins = workMins - (hour * 60);
                                                            }
                                                            if (min > 0) {
                                                                workMins = workMins - (min);
                                                            }
                                                            if (second > 0) {
                                                                workMins = workMins - (second / 60);
                                                            }
                                                        }
                                                        list.get(i).setAddWorkTime(String.valueOf(workMins));
                                                    }
                                                    if (list.get(i).getCheckInTime1Str() != null) {
                                                        absenteeism = 0;
                                                        list.get(i).setAbsenteeism(absenteeism);
                                                    }
                                                } else {
                                                    if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                        if (list.get(i).getCheckOutTime1Str() == null) {
                                                            absenteeism = 1;
                                                            list.get(i).setAbsenteeism(absenteeism);
                                                        }
                                                    }
                                                }
                                                if (list.get(i).getCheckOutTime1Str() != null) {
                                                    if (list.get(i).getCheckInTime2Str() != null) {
                                                        String[] checkInTime = list.get(i).getCheckInTime2Str().split(":");
                                                        int hour = Integer.valueOf(checkInTime[0]) * 60;
                                                        if (hour < paramBeanList.get(0).getAbsenteeism()) {
                                                            absenteeism = 0;
                                                            continue;
                                                        }else {
                                                            absenteeism = 1;
                                                            continue;
                                                        }
                                                    }
                                                }
                                            }
                                            if (paramBeanList.get(0).getOnDutyNoAttend() == 2 || paramBeanList.get(0).getOffDutyNoAttend() == 2) {
                                                if (list.get(i).getCheckInTime1Str() == null) {
                                                    absenteeism = 1;
                                                    list.get(i).setAbsenteeism(absenteeism);
                                                    list.get(i).setAllWorkTime(null);
                                                }
                                            }
                                        }
                                    }
                                    int a = list1.size() - 1;
                                    if (j == a) {
                                        if (absenteeism != 0) {
                                            absenteeism = 1;
                                            list.get(i).setAbsenteeism(absenteeism);
                                        }
                                    }
                                }
                            }
                            if (list1.size() <= 0) {
                                if (absenteeism != 0) {
                                    absenteeism = 1;
                                    list.get(i).setAbsenteeism(absenteeism);
                                }
                            }
                        }
                    }
                }
//                list.get(i).setLateArrive(lateArrive);
//                list.get(i).setLeaveEarly(leaveEarly);
                list.get(i).setAbsenteeism(absenteeism);
                if (absenteeism == 1) {
                    LeaveClass1Bean leaveClass1Bean = new LeaveClass1Bean();
                    leaveClass1Bean.setLeaveName("旷工");
                    List<LeaveClass1Bean> beanList = leaveClass1Service.findLeaveClass1List(leaveClass1Bean);
                    list.get(i).setSymbol(beanList.get(0).getReportSymbol());
                }
            }
        }
        return LayuiUtil.data(count, list);
    }


    /**
     * Description: 带条件查询班次管理记录
     *
     * @param bean
     */
    @RequestMapping("findNumRunBeanById")
    @ResponseBody
    public Object findNumRunBeanById(NumRunBean bean) {
        List<NumRunBean> list = numRunService.findNumRunNameById(bean);
        if (list == null) {
            UserOfRunDeilBean userOfRunDeilBean = new UserOfRunDeilBean();
            userOfRunDeilBean.setSchClassId(bean.getSchClassId());
            List<UserOfRunDeilBean> runDeilList = userOfRunDeilService.findUserOfRunDeilBean(userOfRunDeilBean);
            if (runDeilList != null) {
                return runDeilList;
            }
        }
        return list;
    }
}
